// ==============================================================================================
// MainForm.cs
//
// Created by: NI, 2007.03.26
// ==============================================================================================
using System.Windows.Forms;
using RibbonExplorer.InfoPanel;
using RibbonExplorer.Properties;
using RibbonExplorer.Storage;
using RibbonExplorer.Tree;

namespace RibbonExplorerClient
{
  // ==============================================================================================
  /// <summary>
  /// This class represents the main form of Office RibbonXplorer
  /// </summary>
  // ==============================================================================================
  public partial class MainForm : Form
  {
    #region Lifecycle methods

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Initializes the application main form instance.
    /// </summary>
    // --------------------------------------------------------------------------------------------
    public MainForm()
    {
      InitializeComponent();
      RibbonInfoPanel infoPanel = new RibbonInfoPanel(InfoPanelPlaceHolder);
      new RibbonTree(OfficeRibbonTree, infoPanel);
    }

    #endregion
    
    #region Form events

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Expands the selected node of the tree.
    /// </summary>
    /// <param name="sender">Sender of the event</param>
    /// <param name="e">Event arguments</param>
    // --------------------------------------------------------------------------------------------
    private void ExpandAllToolStripMenuItem_Click(object sender, System.EventArgs e)
    {
      TreeNode selNode = OfficeRibbonTree.SelectedNode;
      if (selNode != null)
      {
        if (selNode is RibbonTreeNode || 
          selNode is TabSetTreeNode ||
          selNode is RootTreeNode ||
          selNode is OfficeAppTreeNode)
        {
          selNode.Expand();
        }
        else
        {
          selNode.ExpandAll();
        }
      }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Collapses the selected node of the tree.
    /// </summary>
    /// <param name="sender">Sender of the event</param>
    /// <param name="e">Event arguments</param>
    // --------------------------------------------------------------------------------------------
    private void CollapseAllToolStripMenuItem_Click(object sender, System.EventArgs e)
    {
      TreeNode selNode = OfficeRibbonTree.SelectedNode;
      if (selNode != null)
      {
        selNode.Collapse(false);
      }
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Closes the application.
    /// </summary>
    /// <param name="sender">Sender of the event</param>
    /// <param name="e">Event arguments</param>
    // --------------------------------------------------------------------------------------------
    private void exitToolStripMenuItem_Click(object sender, System.EventArgs e)
    {
      Close();
    }

    // --------------------------------------------------------------------------------------------
    /// <summary>
    /// Displays the about dialog
    /// </summary>
    /// <param name="sender">Sender of the event</param>
    /// <param name="e">Event arguments</param>
    // --------------------------------------------------------------------------------------------
    private void aboutToolStripMenuItem_Click(object sender, System.EventArgs e)
    {
      AboutForm form = new AboutForm();
      form.ShowDialog();
    }

    #endregion
  }
}